﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;

/// <summary>
/// 普通文件类
/// </summary>
public class CommFiles
{
    private DBOperation _db=new DBOperation();
    private  string _fileName;
    public string FileName
    {
        set { _fileName = value; }
        get { return _fileName; }
    }
	public CommFiles()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    public CommFiles(string fileName)
    {
        _fileName = fileName;
    }
    /// <summary>
    /// 记录上传文件
    /// </summary>
    /// <param name="sqlList">插入数据库的sql语句数组</param>
    /// <returns>成功返回真、否则假</returns>
    
    public bool UploadFile(ArrayList sqlList)
    {
        bool seccess = false;
        seccess = _db.ExcuteSqls(sqlList);
        return seccess;
    }
    /// <summary>
    /// 删除文件记录
    /// </summary>
    /// <param name="fileID">文件ID</param>
    /// <returns>成功返回真，否则假</returns>
    public bool DelectFile(int fileID)
    {
        bool seccess = false;
        string  strDelete = "delete from commFiles where fileID="+fileID;
        seccess = _db.ExcuteSql(strDelete);
        return seccess;

    }
    /// <summary>
    /// 读取所有普通文件的记录
    /// </summary>
    /// <returns>dataSet</returns>
    public DataSet ReadFilesRecord()
    {
        DataSet ds = null;
        string strRead = "select * from commFiles";
        string tableName = "commFiles";
        ds = _db.GetDataSet(strRead,tableName);
        return ds;

    }
    /// <summary>
    /// 根据文件名判断是否已经存在同名的文件
    /// </summary>
    /// <param name="fileName">文件名</param>
    /// <returns>如果存在返回真</returns>
    public bool FindFile(string fileName)
    {
        bool seccess = false;
        int count = 0;
        string findFile = "select count(*) from commFiles where fileName='"+fileName+"'";
        count = Convert.ToInt32(_db.ExcuteScalar(findFile));
        if(count>0)
        {
            seccess = true;
        }
        return seccess;

    }
    /// <summary>
    /// 删除所有
    /// </summary>
    /// <param name="sqlList">sql语句数组</param>
    /// <returns>成功返回真</returns>
    public bool DeleteAll(ArrayList sqlList)
    {
        bool seccess = false;
        seccess=  _db.ExcuteSqls(sqlList);
        return seccess;
       
    }

}
